//显示登录框
var loginBtn = document.querySelector('header .member > div')
loginBtn.onclick = function(){
    var LoginDialog = document.querySelector('section.login')
    LoginDialog.style.visibility = 'visible'
}
// 隐藏登录框
var loginCloseBtn = document.querySelector('section.login i.icon-close')
loginCloseBtn.onclick = function(){
    var LoginDialog = document.querySelector('section.login')
    LoginDialog.style.visibility = 'hidden'
}
// 登录对话框-蓝色区域拖拽
var LoginBlueBox = document.querySelector('section.login .menu')
LoginBlueBox.onmousedown = function(evt){
    var oldE = evt || window.event

    document.onmousemove = function(evt){
        var e = evt || window.event
        var left = e.clientX - oldE.offsetX
        var top = e.clientY - oldE.offsetY 
        if(left < 0) left = 0
        if(top < 0) top = 0
        var LoginDialog = document.querySelector('section.login .item')
        var maxLeft = (window.innerWidth || document.documentElement.clientWidth) - LoginDialog.offsetWidth
        var maxTop = (window.innerHeight || document.documentElement.clientHeight) - LoginDialog.offsetHeight
        if(left > maxLeft) left = maxLeft
        if(top > maxTop) top = maxTop
 
        LoginDialog.style.position = 'absolute'
        LoginDialog.style.left = left + 'px'
        LoginDialog.style.top = top + 'px'
    }
    document.onmouseup = function(){
        document.onmousemove = null
    }
}
//登录倒计时
var num = 5
var captchaBtn = document.querySelector('section.login .captcha')
captchaBtn.onclick = function(){
    //获取行为验证码对话框
    var captchaObj = document.querySelector('section.captcha')
    captchaObj.style.visibility = 'visible'
    document.querySelector('section.captcha i.icon-close').onclick = function(){
    captchaObj.style.visibility = 'hidden'    
    }
    //获取圆球绑定鼠标按下事件
    var dragBtn = captchaObj.querySelector('.drag .btn')
    dragBtn.onmousedown =function(){
    document.onmousemove = function(evt){
        var e = evt || window.event
        var left = e.clientX - (captchaObj.offsetLeft-captchaObj.offsetWidth/2) - dragBtn.offsetWidth
        dragBtn.style.left = left +'px'
        captchaObj.querySelector('.check img:nth-of-type(2)').style.left = left + 'px'
    }
    document.onmouseup = function(){
        document.onmousemove = null
        var value = parseInt(dragBtn.style.left)
        if(value >= 260 && value <=265){
            captchaObj.style.visibility = 'hidden'


    captchaBtn.innerText = num+'秒后重发'
    captchaBtn.disabled = true
    t = setInterval(function(){
        if(num<=1){
            clearInterval(t)
            captchaBtn.innerText = '重新发送'
            num = 5
            captchaBtn.disabled = false
            return
        }
        num--
        captchaBtn.innerText = num+'秒后重发'
    },1000)
}
    dragBtn.style.left = '0px'
    captchaObj.querySelector('.check img:nth-of-type(2)').style.left = '0px'
    }
  }
  return
}

//登录表单验证
var loginSubmitBtn = document.querySelector('section.login .submit')
loginSubmitBtn.onclick = function(){
    var isOk = 0
    var mobileObj = document.querySelector('.login .mobile')
    if(mobileObj.value == '' || mobileObj.value.length != 11 || !Number(mobileObj.value)){
        document.querySelector('section.login .form > p:nth-of-type(3)').innerText = '手机格式有误'
    }else{
        isOk++
        document.querySelector('section.login .form > p:nth-of-type(3)').innerText = ''
    }
    var passwordObj = document.querySelector('.login .password')
    if(passwordObj.value == '' || passwordObj.value.length != 4 || !Number(passwordObj.value)){
        document.querySelector('section.login .form > p:nth-of-type(4)').innerText = '验证码只有四位数字'
    }else{
        isOk++
        document.querySelector('section.login .form > p:nth-of-type(4)').innerText = ''
    }
    if(isOk==2){
        alert('登录成功！')
    }
}

